package com.xdtech.play.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.xdtech.play.service.PlayTradeRecordService;
import com.xdtech.play.vo.PlayTradeRecordItem;
import com.xdtech.sys.aspect.SystemControllerLog;
import com.xdtech.web.controller.BaseController;
import com.xdtech.web.model.Pagination;
import com.xdtech.web.model.ResultMessage;

/**
 * 
 * @author max.zheng
 * @create 2016-05-08 23:42:57
 * @since 1.0
 * @see
 */
@Controller
@Scope("prototype")
public class PlayTradeRecordController extends BaseController{
	private Log log = LogFactory.getLog(PlayTradeRecordController.class);
	@Autowired
	private PlayTradeRecordService playTradeRecordService;
	@RequestMapping(value="/playTradeRecord.do",params = "playTradeRecord")
	public ModelAndView skipPlayTradeRecord() {
		return new ModelAndView("play/playTradeRecord/playTradeRecord_ftl");
	}
	
	@RequestMapping(value="/playTradeRecord.do",params="loadList")
	@ResponseBody
	public Map<String, Object> loadList(PlayTradeRecordItem item,Pagination pg) {
		Map<String, Object> results =  playTradeRecordService.loadPageDataByConditions(pg,item,"findPlayTradeRecordByCondition");
		return results;
	}
	@RequestMapping(value="/playTradeRecord.do",params = "inPlayAccount")
	@ResponseBody
	@SystemControllerLog(description = "资金充值")
	public ResultMessage inPlayAccount(PlayTradeRecordItem item) {
		ResultMessage r = playTradeRecordService.inPlayAccount(item);
		return r;
	}
	
	@RequestMapping(value="/playTradeRecord.do",params = "outPlayAccount")
	@ResponseBody
	@SystemControllerLog(description = "资金提取")
	public ResultMessage outPlayAccount(PlayTradeRecordItem item) {
		ResultMessage r = playTradeRecordService.outPlayAccount(item);
		return r;
	}
	
	
	@RequestMapping(value="/playTradeRecord.do",params = "editPlayTradeRecord")
	@SystemControllerLog(description = "编辑")
	public ModelAndView editPlayTradeRecord(HttpServletRequest request,Long playTradeRecordId) {
		if (playTradeRecordId!=null) {
			request.setAttribute("playTradeRecordItem", playTradeRecordService.loadPlayTradeRecordItem(playTradeRecordId));
		}
		return new ModelAndView("play/playTradeRecord/editPlayTradeRecord_ftl");
	}
	
	@RequestMapping(value="/playTradeRecord.do",params = "savePlayTradeRecord")
	@ResponseBody
	@SystemControllerLog(description = "保存")
	public ResultMessage savePlayTradeRecord(PlayTradeRecordItem item) {
		ResultMessage r = new ResultMessage();
		if (playTradeRecordService.saveOrUpdatePlayTradeRecord(item)) {
			r.setSuccess(true);
		}else {
			r.setSuccess(false);
		}
		return r;
	}
	
	@RequestMapping(value="/playTradeRecord.do",params = "deletePlayTradeRecordItems")
	@ResponseBody
	@SystemControllerLog(description = "删除")
	public ResultMessage deletePlayTradeRecordItems(String ids) {
		ResultMessage r = new ResultMessage();
		if (StringUtils.isNotEmpty(ids)) {
			String[] tempIds = ids.split(",");
			List<Long> playTradeRecordIds = new ArrayList<Long>();
			for (String id : tempIds) {
				playTradeRecordIds.add(Long.valueOf(id));
			}
			playTradeRecordService.deletePlayTradeRecordInfo(playTradeRecordIds);
			r.setSuccess(true);
		}else {
			r.setSuccess(false);
		}
		return r;
	}

}
